<?php
namespace Admin\Controller;
use Think\Controller;
class AlbumController extends VController {
    public function index(){
        $Album_photo_modle = M('Album_photo');
        $count = $Album_photo_modle->where('state=0')->count();
        $Page = new \Think\Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输
        $Album_photoList = $Album_photo_modle->where(array('state'=>0))->limit($Page->firstRow.','.$Page->listRows)->select();
        // dump($Album_photoList);exit;
        $this->assign('Album_photoList',$Album_photoList); 
        $this->assign('page',$show); 
        $this->display();
    }

    public function delete(){
        $log_modle = M('Album_photo');
        $logList = $log_modle->where(array('state'=>4))->select();
        $this->assign('photoList',$logList);
        $this->display();
    }

    //恢复日志
    public function back(){
        if(IS_AJAX){
            $id=I('post.id');
            $data['state']=0;
            $log_modle = M('Album_photo');
            $res = $log = $log_modle->where(array('id'=>$id))->save($data);
            if($res){
                $rs['status'] = 'success';
                $rs['msg'] = '恢复成功';
                $rs['str'] = '删除';
                $rs['state'] = '0';
                $this->ajaxReturn($rs);
            }else{
                $rs['status'] = 'failed';
                $rs['msg'] = '恢复失败';
                $this->ajaxReturn($rs);
            }
        }else{
            $this->error('非法请求！');
        }
    }

     //删除日志
    public function del(){
        if(IS_AJAX){
            $id=I('post.id');
            $data['state']=4;
            $log_modle = M('Album_photo');
            $res = $log = $log_modle->where(array('id'=>$id))->save($data);
            if($res){
                $rs['status'] = 'success';
                $rs['msg'] = '删除成功';
                $rs['str'] = '恢复';
                $rs['state'] = '4';
                $this->ajaxReturn($rs);
            }else{
                $rs['status'] = 'failed';
                $rs['msg'] = '删除失败';
                $this->ajaxReturn($rs);
            }
        }else{
            $this->error('非法请求！');
        }
    }
}